import { EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { RoundInfo, RecmInfo } from "../ExecutePlan";
import { IRecmStrategy } from "../IRecmStrategy";
import { ICopy } from "../ICopy";

export class BossRecmOptionItemV3 implements ICopy {
    copyValue(valueObj: any): void {
        var obj = valueObj as BossRecmOptionItemV3;
        if(obj !=null){
            this.result = obj.result;
            this.recmArray.splice(0,this.recmArray.length,...obj.recmArray);
        }
    }
    recmArray: EnumBjlResult[] = [];
    result: EnumBjlResult = EnumBjlResult.U;
}
export class BossRecmOptionV3 {
    graphics: BossRecmOptionItemV3[] = [];

    /**
    * 0:正常兔子
    * 1:快一步兔子
    * 2:保守兔子
    * 3:阶梯兔子
    * 4:平推兔子
    * 5:固定兔子
    */
    rabbitType: string = "0";
    /**
     * 保守兔子的时候上线倍数
     */
    extendMultiple: number = 0;
    gameMultiple:number = 1;
}

export class BossRecmStrategyV3 implements IRecmStrategy {
    graphicArray: BossRecmOptionItemV3[] = [];
    /**
    * 0:正常兔子
    * 1:快一步兔子
    * 2:保守兔子
    * 3:阶梯兔子
    * 4:平推兔子
    * 5:固定兔子
    */
    protected _rabbitType: string = "0";
    public get rabbitType() {
        return this._rabbitType;
    }
    public set rabbitType(value: string) {
        this._rabbitType = value;
    }
    /**
     * 保守兔子的时候上线倍数
     */
    protected _extendMultiple: number = 0;
    public get extendMultiple() {
        return this._extendMultiple;
    }
    public set extendMultiple(value: number) {
        this._extendMultiple = value;
    }

    constructor(name: string, option?: BossRecmOptionV3) {
        this.strategyName = name;
        if (option) {
            this.graphicArray = option.graphics;
            this._rabbitType = option.rabbitType;
            this._extendMultiple = option.extendMultiple;
        }
        else {
            this.graphicArray = [];
            this._rabbitType = "0";
            this._extendMultiple = 10;
        }

    }
    setResult(roundInfo: RoundInfo, recmInfo: RecmInfo, multiple: number, waterRate: number, fuliRate: number): void {
        return;
    }
    toResult(roundInfo: RoundInfo): EnumBjlResult {
        let strResult = roundInfo.results.join('');
        let recmItem = this.graphicArray.filter(it => strResult.endsWith(it.recmArray?.join('') ?? ""));
        let recm = recmItem.sort((a,b)=>b.recmArray.length - a.recmArray.length)[0];
        if(recm){
            return recm.result;
        }
        //let iv = 0;
        // for (let i = 0; i < recmItem.length; i++) {
        //     if (recmItem[i].result == EnumBjlResult.Z) {
        //         iv++;
        //     }
        //     else if (recmItem[i].result == EnumBjlResult.X) {
        //         iv--;
        //     }
        // }
        // if (iv > 0) {
        //     return EnumBjlResult.Z;
        // }
        // else if (iv < 0) {
        //     return EnumBjlResult.X;
        // }
        return EnumBjlResult.U;
    }
    strategyName: string = '';
    debugCompoenent: string = '';
    resetRecm(): void {

    }
    copyValue(valueObj: any): void {
        var obj = valueObj as BossRecmStrategyV3;
        if (obj) {
            //this.graphicArray = obj.graphicArray;
            this.rabbitType = obj.rabbitType;
            this.extendMultiple = obj.extendMultiple;
            this.graphicArray.splice(0,this.graphicArray.length);
            if(obj.graphicArray!=null && obj.graphicArray.length > 0){
                obj.graphicArray.forEach(item=>{
                    var it = new BossRecmOptionItemV3();
                    it.copyValue(item);
                    this.graphicArray.push(it);
                });
            }
        }
    }

    getRecm() {
        return this.graphicArray;
    }
    removeGraphic(idx: number) {
        this.graphicArray.splice(idx, 1);
    }
    addGraphic(item: BossRecmOptionItemV3) {
        this.graphicArray.push(item);
    }
}